﻿using BoriPeter.FitnessJournal8.Models;
using Caliburn.Micro;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BoriPeter.FitnessJournal8.ViewModels
{
    public class FoodDetailsViewModel : ViewModelBase
    {
        #region Constructor
        public FoodDetailsViewModel(INavigationService navigationService)
            : base(navigationService)
        {

        }
        #endregion

        #region Food
        private Food food;
        public Food Food
        {
            get
            {
                return this.food;
            }

            set
            {
                this.food = value;
                NotifyOfPropertyChange("Food");
            }
        }
        #endregion

        #region Id
        private int id;
        private string paramId;
        public string ParamId
        {
            set 
            {
                paramId = value;
                id = int.Parse(value);
            }
            get
            {
                return paramId;
            }
        }
        #endregion

        #region AddNew()
        public void AddNew()
        {
            Navigate2AddNewEntry(food);
        }

        public void AddNew2()
        {
            Navigate2AddNewEntry(food);
        }
        #endregion

        #region AddFavorite()
        public async void AddFavorite()
        {
            Food.Favorite = true;
            Food.FavoriteNotStored = true;
            await NutritionSource.SaveAsync(Food);
        }
        #endregion

        #region DeleteFavorite()
        public async void DeleteFavorite()
        {
            Food.Favorite = false;
            Food.FavoriteNotStored = true;
            await NutritionSource.SaveAsync(Food);
        }
        #endregion

        #region OnInitialize()
        protected override async void OnInitialize()
        {
            base.OnInitialize();

            if (id != 0)
                Food = await NutritionSource.GetByIdAsync(id);

            ProgressBarIsIndeterminate = false;
        }
        #endregion
    }
}
